package com.panda.admin.login.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.panda.admin.login.dto.PasswordDto;
import com.panda.admin.login.entity.SystemCaptcha;
import com.panda.admin.login.entity.SystemUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author tucy123
* @description 针对表【system_user(用户表)】的数据库操作Mapper
* @createDate 2022-10-27 09:26:47
* @Entity com.panda.admin.login.auth.MallUser
*/
@Mapper
public interface SystemUserMapper extends BaseMapper<SystemUser> {

    /**
     * 查询默认账号等级
     * @return
     */
    @Select("select id from mall_user_level where common_status = 1 and default_status = 1")
    Long queryDefaultLevel();

    /**
     * 保存验证码
     * @param systemCaptcha
     */
    @Insert("insert into system_captcha value (#{systemCaptcha.uuid},#{systemCaptcha.captcha},#{systemCaptcha.expireTime},#{systemCaptcha.createTime},#{systemCaptcha.updateTime},#{systemCaptcha.commonStatus})")
    void mathSaveCaptcha(@Param("systemCaptcha") SystemCaptcha systemCaptcha);

    /**
     * 删除过期的验证码
     * @return
     */
    @Delete("delete from system_captcha where expire_time < now()")
    Boolean deleteExpireCaptcha();

    /**
     * 校验验证码
     * @param uuid
     * @param captcha
     * @return
     */
    @Select("select  * from system_captcha where uuid = #{uuid} and captcha = #{captcha} and common_status = 1")
    List<SystemCaptcha> checkCaptcha(@Param("uuid") String uuid, @Param("captcha") String captcha);

    /**
     * 删除验证码
     * @param uuid
     */
    @Delete("delete from system_captcha where uuid = #{uuid}")
    void deleteCaptcha(@Param("uuid") String uuid);

    /**
     * 修改密码
     * @param passwordDto
     * @return
     */
    @Update("update system_user set password = #{passwordDto.newPassword} where id = #{passwordDto.id}")
    boolean updatePassword(@Param("passwordDto") PasswordDto passwordDto);
}
